<?php session_start();
header('P3P: CP="CAO PSA OUR"');
	//require_once("utils/session.php");
	require_once("utils/redirect.php");
 
	if (isset($_SESSION['facebookID']))
		unset($_SESSION['facebookID']);
 
	$app_id = "192488190793025";
	
	$canvas_page = "http://apps.facebook.com/testinguntold/";
	
	$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" .
		$app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email";
	$untold_url = "http://testsite.untoldthegame.com/";
	
	$signed_request = $_REQUEST["signed_request"];
	
	list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
	
	$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
	
	if (empty($data["user_id"]))
	{
		echo("<script> top.location.href='" . $auth_url . "'</script>");
	}
	
	$_SESSION['facebookID'] = $data["user_id"];
	
	redirect("http://testcb.untoldthegame.com/facebooktesting/www/login.php/");
?>
